<template>
  <div class="login-wrap">
    <div class="ms-login">
      <div class="ms-title">欢迎登录</div>
      <el-form
        :model="param"
        :rules="rules"
        ref="login"
        label-width="0px"
        class="ms-content"
      >
        <el-form-item prop="username">
          <el-input v-model="param.username" placeholder="输入账号">
            <el-button slot="prepend" icon="el-icon-user"></el-button>
          </el-input>
        </el-form-item>
        <el-form-item prop="password" style="margin-top: 25px">
          <el-input
            type="password"
            placeholder="登录密码"
            v-model="param.password"
            @keyup.enter.native="submitForm()"
          >
            <el-button slot="prepend" icon="el-icon-lock"></el-button>
          </el-input>
        </el-form-item>
        <div class="login-btn">
          <el-button type="primary" @click="submitForm()">登录</el-button>
          <span>注：账号admin密码123456</span>
        </div>
      </el-form>
    </div>
  </div>
</template>
  
  <script>
import axios from "axios";
import request from "@/util/request";
import qs from "qs";
//import { setRoutes } from "@/router";

export default {
  name: "Login", // 登录页面
  data() {
    return {
      param: {
        username: "",
        password: "",
      },
      rules: {
        username: [
          { required: true, message: "账号不能为空", trigger: "blur" },
        ],
        password: [
          { required: true, message: "密码不能为空", trigger: "blur" },
        ],
      },
    };
  },
  created() {},
  methods: {
    submitForm() {
      this.$refs.login.validate((valid) => {
        if (valid) {
          var t = new FormData();
          t.append("username", this.param.username);
          t.append("password", this.param.password);
          let config = {
            headers: {
              "Content-type": "application/x-www-form-urlencoded", // 设置完以后 传入的 params对象就会用formdata传参的方式
            },
          };
          axios({
            method: "post",
            url: "/user/login",
            data: {
              username: this.param.username,
              password: this.param.password,
            },
            headers: {
              "Content-Type": "application/x-www-form-urlencoded",
            },
          })
            .then((res) => {
              console.log(res);
              if (res.data.flag) {
                this.$notify.success("操作成功");
                sessionStorage.setItem("user", JSON.stringify(res.data.data));
                this.$router.push("/");
              } else {
                this.$notify.error(res.msg);
                this.getTableData();
              }
            })
            .catch((err) => {
              console.log(err);
            });
        } else {
          this.$message.error("请输入账号和密码");
          console.log("error submit!!");
          return false;
        }
      });
    },
  },
};
</script>
  
  <style scoped>
.login-wrap {
  position: absolute;
  width: 100%;
  height: 100%;
  background: url("../assets/QQ图片20230623092752.jpg");
}
.ms-title {
  width: 100%;
  text-align: center;
  font-size: 22px;
  margin: 25px 0px 15px;
}
.ms-login {
  position: relative;
  width: 450px;
  height: 335px;
  max-width: 90%;
  margin: 275px auto;
  border-radius: 5px;
  background: white;
  overflow: hidden;
}
.ms-content {
  padding: 30px 30px;
}
.login-btn {
  margin-top: 10%;
}
.login-btn button {
  width: 100%;
  height: 36px;
  text-align: center;
  margin-bottom: 10px;
}
</style>
  